<?php

namespace ModStart\Util;

use ModStart\Util\Exception\UtilException;

class FileUtil
{
    public static function generateLocalTempPath($base, $ext = 'tmp')
    {
        $base = rtrim($base, '/\\') . '/';
        if (!file_exists($base)) {
            @mkdir($base, 0755, true);
        }
        for ($i = 0; $i < 10; $i++) {
            $tempPath = $base . RandomUtil::lowerString(32) . '.' . $ext;
            if (!file_exists($tempPath)) {
                return $tempPath;
            }
        }
        UtilException::throws('FileUtil generateLocalTempPath error');
    }

}
